package com.atguigu.spzx.controller;

import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/system")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;


    @PostMapping(value = "/fileUpload")
    public Result<String> fileUploadService(@RequestParam(name = "file") MultipartFile file) {
        //从前端往后传递文件需要用 MultipartFile接收 变量名称是前端 input的name名称,如果名称不一致,数据无法接收
        // 获取上传的文件
        String fileUrl = fileUploadService.fileUpload(file);
        return Result.build(fileUrl, ResultCodeEnum.SUCCESS);
    }
}
